<template>
    <div class="Infom">
        <van-nav-bar title="商品详情" left-arrow left-text="返回" @click-left="$goBack" />
        <div v-if="selectedProduct">
            <img :src="selectedProduct.goodsCoverImg" alt="商品图片">
            <h3>{{ selectedProduct.goodsName }}</h3>
            <p>{{ selectedProduct.goodsIntro }}</p>
            <p style="color: #999;">免邮费 顺丰快递</p>
            <span id="fc">￥{{ infomData2.sellingPrice }}</span>
            <div class="button-group">
                <van-button class="but1">加入购物车</van-button>
                <van-button class="but2">立即购买</van-button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        goodsId: {
            type: [String, Number],
            required: true, // 确保 goodsId 是必传的
        }
    },
    data() {
        return {
            infomData2: {
                goodsCoverImg: null,
                goodsName: '',
                goodsIntro: '',
                sellingPrice: 0,
            },
        };
    },
    created() {
        if (this.goodsId) {
            this.loadProductDetails();
        }
    },
    methods: {
        selectProduct(product) {
            // 更新 Vuex 中的 selectedProduct
            this.$store.dispatch('selectProduct', product);
        }
    },
    computed: {
        selectedProduct() {
            return this.$store.getters.selectedProduct;
        }
    }

};
</script>

<style scoped lang="less">
.Infom {
    text-align: center;
}

#fc {
    color: #ff0000;
}

img {
    width: 200px;
    height: 200px;
}

p {
    margin-left: 15px;
    text-align: left;
    font-size: 14px;
}

span {
    margin-left: 15px;
    display: block;
    text-align: left;
    font-size: 18px;
}

.button-group {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    padding-top: 180px;
}

.but1 {
    background-color: #87CEEB; // 浅蓝色背景
    color: white;
    border: none;
    border-radius: 25px 0 0 25px; // 左半边圆角
    padding: 10px 20px;
    flex: 1;
    margin-left: 10px;
}

.but2 {
    background-color: #00CED1; // 深蓝色背景
    border: none;
    border-radius: 0 25px 25px 0; // 右半边圆角
    padding: 10px 20px;
    flex: 1;
    margin-right: 10px;
    color: white;
}
</style>